package entity;

import lombok.Getter;

import java.util.regex.*;

@Getter
public class CreditCard {
    protected String number;
    protected String holderName;
    public boolean isValid(String number){
        if (number == null) {
            return false;
        }

        String regex = "\\d{1,19}";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(number);
        return matcher.matches();
    }

    public CreditCard setNumber(String number){
        this.number = number;
        return this;
    }

    public CreditCard setHolderName(String holderName){
        this.holderName = holderName;
        return this;
    }

    public String getIssuer(){
        return "";
    }

    public CreditCard build(){
        return this;
    }

    @Override
    public String toString() {
        return number + " " + holderName + "\n";
    }

    public CreditCard getInstance(){
        return new CreditCard();
    }
}
